#define _CRT_SECURE_NO_WARNINGS 

#include"stack.h"

void initst(st* pst)
{
	pst->top = -1;
	pst->capacity = 0;
	pst->a = NULL;
}

void pushback(st* pst,stdatetype x)
{
	assert(pst);

	if ((pst->top + 1) == pst->capacity)
	{
		pst->capacity = pst->capacity == 0 ? 4 : pst->capacity * 2;
		stdatetype* tail = (stdatetype*)realloc(pst->a, sizeof(stdatetype)*pst->capacity);

		assert(tail);
		pst->a = tail;
	}

	pst->a[++(pst->top)] = x;
}

void popback(st* pst)
{
	assert(pst->top > -1);

	pst->top--;
}

//void printst(st* pst)
//{
//	assert(pst);
//
//	for (int i = 0; i <= pst->top; i++)
//	{
//		printf("%d--",pst->a[i]);
//	}
//}

stdatetype sttop(st* pst)
{
	assert(pst);
	assert(pst->top > -1);

	return pst->a[pst->top];
}
int sizest(st* pst)
{
	assert(pst);

	return pst->top + 1;
}

bool empty(st* pst)
{
	assert(pst);

	return pst->top == -1;
}

void destroy(st* pst)
{
	assert(pst);

	free(pst->a);
	pst->a = NULL;
	pst->top = -1;
	pst->capacity = 0;

}